# 华山 读《正气诀》
import functools, asyncio, re
from pymud import Alias, Trigger, SimpleCommand, SimpleTrigger, SimpleAlias, Timer

class Configuration:
    def __init__(self, session) -> None:
        self.session = session
        self._timers = {}
        self._triggers = {}
        self._initTriggers()
        self._initTimers()

    def _initTriggers(self):
        self._triggers["tri_1"] = Trigger(self.session,
            r"^你现在已经过于疲倦，无法继续研读新知。|^你现在太累了，结果一行也没有看下去。",
            group="tri_dushu", id="tri_1",
            onSuccess = self._onTriggersStop
        )
        self.session.addTriggers(self._triggers)

    def _onTriggersStop(self, name, line, wildcards):
        self.session.enableGroup("ti_dushu", False)
        self.session.create_task(self._asyncStart(wildcards))
    async def _asyncStart(self, wildcards):
        await asyncio.sleep(60)
        self.session.writeline('fangqi zhengqijue to 0;a111111')
        await asyncio.sleep(2)
        self.session.enableGroup("ti_dushu", True)

    def _initTimers(self):
        self._timers["ti_dushu"] = Timer(
            self.session, timeout=5, id="ti_dushu", group="ti_dushu",
            onSuccess=self._onTimerRead
        )
        self.session.addTimers(self._timers)
    def _onTimerRead(self, name, *args, **kwargs):
        self.session.writeline('study zhengqi_book 150')